<template>
    <page-layout>
        <page-header slot="header" title="演示模块"></page-header>
        <div class="content">
            <div class="content-item">
                <p class="content-item__title">用户模块</p>
                <div>
                    <isc-button size="small" @click="reqresFun('创建角色')">创建角色</isc-button>
                    <isc-button size="small" @click="reqresFun('创建用户')">创建用户</isc-button>
                    <isc-button size="small" @click="reqresFun('用户登录')">用户登录</isc-button>
                    <isc-button size="small" @click="reqresFun('获取用户信息')">获取用户信息</isc-button>
                    <isc-button size="small" @click="reqresFun('获取功能权限菜单')">获取功能权限菜单</isc-button>
                </div>
            </div>
            <div class="content-item">
                <p class="content-item__title">设备模块</p>
                <div>
                    <isc-button size="small" @click="reqresFun('创建设备类')">创建设备类</isc-button>
                    <isc-button size="small" @click="reqresFun('创建设备')">创建设备</isc-button>
                    <!-- <isc-button size="small" @click="reqresFun('调用设备能力')">调用设备能力</isc-button> -->
                    <isc-button size="small" @click="reqresFun('修改设备属性')">修改设备属性</isc-button>
                    <isc-button size="small" @click="reqresFun('获取设备详情')">获取设备详情</isc-button>
                    <isc-button size="small" @click="reqresFun('查询设备属性')">查询设备属性</isc-button>
                </div>
            </div>
            <!-- <div class="content-item">
                <p class="content-item__title">基础模块</p>
                <div>
                    <isc-button size="small" @click="reqresFun('上传文件')">上传文件</isc-button>
                    <isc-button size="small" @click="reqresFun('发送消息')">发送消息</isc-button>
                </div>
            </div> -->
            <div class="content-item">
                <p class="content-item__title">调用链路模块</p>
                <div>
                    <isc-button size="small" @click="reqresFun('生成异常信息')">生成异常信息</isc-button>
                    <!-- <isc-button size="small" @click="reqresFun('跳转链路模块')">跳转链路模块</isc-button> -->
                </div>
            </div>
            <div class="content-item">
                <p class="content-item__title">动态配置模块</p>
                <div>
                    <isc-button size="small" @click="reqresFun('获取当前动态配置项')">获取当前动态配置项</isc-button>
                    <!-- <isc-button size="small" @click="reqresFun('修改动态配置项')">修改动态配置项</isc-button> -->
                </div>
            </div>
            <div class="content-item">
                <p class="content-item__title">应用中心模块</p>
                <div>
                    <isc-button size="small" @click="reqresFun('纯前端应用注册')">纯前端应用注册</isc-button>
                    <isc-button size="small" @click="reqresFun('纯后端应用注册')">纯后端应用注册</isc-button>
                    <isc-button size="small" @click="reqresFun('桌面菜单应用注册')">桌面菜单应用注册</isc-button>
                    <isc-button size="small" @click="reqresFun('后台应用注册')">后台应用注册</isc-button>
                    <isc-button size="small" @click="reqresFun('外联应用注册')">外联应用注册</isc-button>
                    <isc-button size="small" @click="reqresFun('轻应用注册')">轻应用注册</isc-button>
                    <isc-button size="small" @click="reqresFun('用户应用卸载')">用户应用卸载</isc-button>
                    <isc-button size="small" @click="reqresFun('应用公私钥注册')">应用公私钥注册</isc-button>
                    <isc-button size="small" @click="reqresFun('获取accessToken')">获取accessToken</isc-button>
                    <!-- <isc-button size="small" @click="reqresFun('生成应用公私钥')">生成应用公私钥</isc-button> -->
                </div>
            </div>
        </div>
        <isc-dialog title="详情" width="1200px" :visible.sync="logVisible">
            <isc-row :gutter="20" class="logs">
                <isc-col :span="12">
                    <p class="logs__title">请求参数</p>
                    <json-viewer :value="reqJsonData" :expand-depth="10" copyable boxed sort></json-viewer>
                </isc-col>
                <isc-col :span="12">
                    <p class="logs__title">响应数据</p>
                    <json-viewer :value="resJsonData" :expand-depth="10" copyable boxed sort></json-viewer>
                </isc-col>
            </isc-row>
            <div>
                <isc-button @click="linkCall(traceid)" class="mt20">参看接口请求链路</isc-button>
            </div>
        </isc-dialog>
    </page-layout>
</template>

<script>
    import {addRole,addUser,login,getUserInfo,getAclList,addProduct,creatDevice,setAttributeValue,getAttributeValue,getDeviceDetail,createErrorForDemo,getDynamicConfig,registerFrontApp,registerBackEndApp,registerMenuApp,registerBackgroundApp,registerOutApp,registerLightApp,deleteApp,registerAppKey,getAccessToken} from './service';
    import { app } from '@isyscore/messenger';
    export default {
        name: 'Index',
        components: {},
        data() {
            return {
                logVisible: false,
                traceid: '',
                reqJsonData: [],  //请求数据
                resJsonData: [],  //响应数据
            };
        },
        computed: {

        },
        watch: {

        },
        created() {

        },

        beforeDestroy() {

        },
        methods: {
            async reqresFun(type){
                if( type ){
                    let reqUrl;
                    let params;
                    if( type==='创建角色' ){
                        reqUrl = addRole;
                        params = {code: 'isc-system'};
                    }else if( type==='创建用户' ){
                        reqUrl = addUser;
                        params = {code: 'isc-system'};
                    }else if( type==='用户登录' ){
                        reqUrl = login;
                        params = {code: 'isc-system'};
                    }else if( type==='获取用户信息' ){
                        reqUrl = getUserInfo;
                        params = {code: 'isc-system'};
                    }else if( type==='获取功能权限菜单' ){
                        reqUrl = getAclList;
                        params = {code: 'isc-system'};
                    }else if( type==='创建设备类' ){
                        reqUrl = addProduct;
                        params = {code: 'isc-system'};
                    }else if( type==='创建设备' ){
                        reqUrl = creatDevice;
                        params = {code: 'isc-system'};
                    }else if( type==='修改设备属性' ){
                        reqUrl = setAttributeValue;
                        params = {code: 'isc-system'};
                    }else if( type==='获取设备详情' ){
                        reqUrl = getDeviceDetail;
                        params = {code: 'isc-system'};
                    }else if( type==='查询设备属性' ){
                        reqUrl = getAttributeValue;
                        params = {code: 'isc-system'};
                    }else if( type==='生成异常信息' ){
                        reqUrl = createErrorForDemo;
                        params = {code: 'isc-system'};
                    }else if( type==='获取当前动态配置项' ){
                        reqUrl = getDynamicConfig;
                        params = {code: 'isc-system'};
                    }else if( type==='纯前端应用注册' ){
                        reqUrl = registerFrontApp;
                        params = {code: 'isc-system'};
                    }else if( type==='纯后端应用注册' ){
                        reqUrl = registerBackEndApp;
                        params = {code: 'isc-system'};
                    }else if( type==='桌面菜单应用注册' ){
                        reqUrl = registerMenuApp;
                        params = {code: 'isc-system'};
                    }else if( type==='后台应用注册' ){
                        reqUrl = registerBackgroundApp;
                        params = {code: 'isc-system'};
                    }else if( type==='外联应用注册' ){
                        reqUrl = registerOutApp;
                        params = {code: 'isc-system'};
                    }else if( type==='轻应用注册' ){
                        reqUrl = registerLightApp;
                        params = {code: 'isc-system'};
                    }else if( type==='用户应用卸载' ){
                        reqUrl = deleteApp;
                        params = {code: 'isc-system'};
                    }else if( type==='应用公私钥注册' ){
                        reqUrl = registerAppKey;
                        params = {code: 'isc-system'};
                    }else if( type==='获取accessToken' ){
                        reqUrl = getAccessToken;
                        params = {code: 'isc-system'};
                    }
                  
                    let data;
                    try {
                        data = await reqUrl(params);
                    } catch (e) {
                        return false;
                    }
                    console.log(data);
                    this.reqJsonData = data.param || [];
                    this.resJsonData = data.result || [];
                    this.traceid = data.traceid;
                    this.logVisible = true;
                }
            },
            linkCall(id){
                console.log(id);
                let url = `#/monitor/chain/chaincall?traceid=${id}`;
                app.navigatorApp('isc-system', url);
            }
        }
    };
</script>

<style lang="scss" scoped>
    .content {
        height: 100%;
        // background: #fff;
        border: 1px solid #eaeaea;

        &-item {
            padding: 20px;
            border: 1px solid #eaeaea;
            background: #fff;
            margin-bottom: 15px;

            &__title {
                font-size: 14px;
                color: #333;
                margin-bottom: 15px;
            }
        }
    }
    .logs{
        &__title{
            font-size: 14px;
            margin-bottom: 10px;
        }
    }
</style>
